package com.lzy.cloud.goods.service.GoodsServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.goods.dtos.CarCategoryDto;
import com.lzy.cloud.goods.entity.CarCategory;
import com.lzy.cloud.goods.mapper.CarCategoryMapperExt;
import com.lzy.cloud.goods.service.CarCategoryService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by WIN7 on 2018/6/9.
 */
@Service
public class CarCategoryServiceImpl implements CarCategoryService {

    @Autowired
    CarCategoryMapperExt carCategoryMapperExt;

    @Override
    public Boolean add(CarCategoryDto dto) {
        return carCategoryMapperExt.insertSelective(DozerUtils.map(dto, CarCategory.class)) > 0;
    }

    @Override
    public Boolean delById(Long id) {
        return carCategoryMapperExt.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public Boolean update(CarCategoryDto dto) {
        return carCategoryMapperExt.updateByPrimaryKeySelective(DozerUtils.map(dto, CarCategory.class)) > 0;
    }

    @Override
    public PageInfo<CarCategoryDto> selectList(Pager pager, CarCategoryDto dto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        return new PageInfo<>(carCategoryMapperExt.selectList(dto));
    }

    @Override
    public CarCategoryDto selectById(Long id) {
        return DozerUtils.map(carCategoryMapperExt.selectByPrimaryKey(id), CarCategoryDto.class);
    }
}
